home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / imagewn.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  4.8 KB  |  121 lines

  1. //----------------------------------------------------------------------------
  2. //Borland C++Builder
  3. //Copyright (c) 1987, 1998 Borland International Inc. All Rights Reserved.
  4. //----------------------------------------------------------------------------
  5.  //---------------------------------------------------------------------
  6. // IMAGE VIEWER DEMO v.01
  7. //---------------------------------------------------------------------
  8. #include <vcl.h>
  9. #pragma hdrstop
  10.  
  11. #include <sysutils.hpp>
  12. #include <stdio.h>
  13. #include "imagewn.h"
  14. #include "ViewFrm.h"
  15. //---------------------------------------------------------------------
  16. #pragma resource "*.dfm"
  17. TImageForm *ImageForm;
  18. //---------------------------------------------------------------------
  19. __fastcall TImageForm::TImageForm(TComponent *Owner)
  20.   : TForm(Owner)
  21. {
  22. }
  23. //---------------------------------------------------------------------
  24. void __fastcall TImageForm::FormCreate(TObject* /*Sender*/)
  25. {     FormCaption = Caption + " - ";
  26. }
  27. //----------------------------------------------------------------------------
  28.  void __fastcall TImageForm::ViewBtnClick(TObject* /*Sender*/)
  29. {     ViewFrm->HorzScrollBar->Range = Image1->Picture->Width;
  30.       ViewFrm->VertScrollBar->Range = Image1->Picture->Height;
  31.       ViewFrm->Caption = Caption;
  32.       ViewFrm->Show();
  33. }
  34. //----------------------------------------------------------------------------
  35.  void __fastcall TImageForm::UpDownEditChange(TObject* /*Sender*/)
  36. {
  37.       SpeedButton1->NumGlyphs = UpDown1->Position;
  38.       SpeedButton2->NumGlyphs = UpDown1->Position;
  39. }
  40. //----------------------------------------------------------------------------
  41.  void __fastcall TImageForm::StretchCheckClick(TObject* /*Sender*/)
  42. {     Image1->Stretch = StretchCheck->Checked;
  43. }
  44. //----------------------------------------------------------------------------
  45. #pragma argsused
  46.  void __fastcall TImageForm::FileEditKeyPress(TObject* Sender,
  47.       Char &Key)
  48. {     if (Key == 0x13) {
  49.          FileListBox1->ApplyFilePath(FileEdit->Text);
  50.          Key = 0x0;
  51.       }
  52. }
  53. //----------------------------------------------------------------------------
  54.  void __fastcall TImageForm::GlyphCheckClick(TObject* /*Sender*/)
  55. {
  56.      ViewAsGlyph(FileExt);
  57. }
  58. //----------------------------------------------------------------------------
  59.  void __fastcall TImageForm::ViewAsGlyph(const AnsiString FileExt)
  60. {
  61.     if ( GlyphCheck->Checked && !strcmp(FileExt.c_str(),".BMP") ) {
  62.          SpeedButton1->Glyph = Image1->Picture->Bitmap;
  63.          SpeedButton2->Glyph = Image1->Picture->Bitmap;
  64.          UpDown1->Position   = SpeedButton1->NumGlyphs;
  65.          BitBtn1->Glyph      = Image1->Picture->Bitmap;
  66.          BitBtn2->Glyph      = Image1->Picture->Bitmap;
  67.          UpDown1->Enabled    = True;
  68.          UpDownEdit->Enabled = True;
  69.          Label2->Enabled     = True;
  70.       }
  71.       else {
  72.          SpeedButton1->Glyph = NULL;
  73.          SpeedButton2->Glyph = NULL;
  74.          BitBtn1->Glyph      = NULL;
  75.          BitBtn2->Glyph      = NULL;
  76.          UpDown1->Enabled    = False;
  77.          UpDownEdit->Enabled = False;
  78.          Label2->Enabled     = False;
  79.       }
  80. }
  81. //----------------------------------------------------------------------------
  82. void __fastcall TImageForm::FileListBox1Click(TObject* /*Sender*/)
  83. {    char cCaption[25];
  84.      memset(cCaption,NULL,sizeof(cCaption));
  85.  
  86.      FileExt = ExtractFileExt(FileListBox1->FileName);
  87.      FileExt = UpperCase(FileExt);
  88.  
  89.      if ( !strcmp(FileExt.c_str(),".BMP") || !strcmp(FileExt.c_str(),".ICO") ||
  90.           !strcmp(FileExt.c_str(),".WMF") || !strcmp(FileExt.c_str(),".EMF" ))
  91.      {
  92.         Image1->Picture->LoadFromFile(FileListBox1->FileName);
  93.         Caption = FormCaption + ExtractFileName(FileListBox1->FileName);
  94.  
  95.         if ( !strcmp(FileExt.c_str(),".BMP") )
  96.         {
  97.            sprintf(cCaption," (%d x %d)",Image1->Picture->Width,Image1->Picture->Height);
  98.            Caption = (AnsiString)cCaption;
  99.            ViewFrm->Image1->Picture = Image1->Picture;
  100.            ViewFrm->Caption = Caption;
  101.            GlyphCheck->Enabled = true;
  102.            if (GlyphCheck->Checked)
  103.                 ViewAsGlyph(FileExt);
  104.         }
  105.         if ( !strcmp(FileExt.c_str(),".ICO") )
  106.         {
  107.              ViewFrm->Image1->Picture->Icon = Image1->Picture->Icon;
  108.              Icon = Image1->Picture->Icon;
  109.              GlyphCheck->Checked = false;
  110.              GlyphCheck->Enabled = false;
  111.         }
  112.         if ( !strcmp(FileExt.c_str(),".WMF") || !strcmp(FileExt.c_str(),".EMF") )
  113.         {
  114.              ViewFrm->Image1->Picture->Metafile = Image1->Picture->Metafile;
  115.              GlyphCheck->Checked = false;
  116.              GlyphCheck->Enabled = false;
  117.         }
  118.      }
  119. }
  120. //----------------------------------------------------------------------------
  121.